<template>
  <div>
    <router-link to="/cart/addAddress"><el-button>添加</el-button></router-link>
    <el-table
      :data="AddressList"
      :stripe="true"
      style="width: 100%">
      <el-table-column
        prop="id"
        label="编号">
      </el-table-column>
      <el-table-column
        prop="receiveName"
        label="收货人">
      </el-table-column>
      <el-table-column
        prop="address"
        label="收货地址">
      </el-table-column>
      <el-table-column
        prop="mobile"
        label="电话">
      </el-table-column>
      <el-table-column
        label="是否默认">
        <template slot-scope="scope">
          {{scope.row.selectedState==0?"否":"是"}}
        </template>
      </el-table-column>

      <el-table-column
        label="操作">
        <template slot-scope="scope">
          <el-button @click="changeState(scope.row.id)">设为默认</el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
    export default {
        name: "AddressList",
      data(){
          return {
            AddressList:[],
            address:{}
          }
      },
      created(){
        //发出ajax请求请求后端代码
        this.selectAll();
      },
      methods:{
          selectAll(){
            this.axios.get("/address/selectByUid").then((resp)=>{
              this.AddressList=resp.data;
            });
          },
        changeState(id){
          this.address.id=id;
          this.axios.put("/address/updateSelected",this.address).then((resp)=>{
            this.$message.success("修改成功！");
            this.selectAll();
          });
        }
      }
    }
</script>

<style scoped>

</style>
